package com.qf.work;

import com.qf.util.MQConnUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Publisher {

    public static final String QUEUE_NAME = "work_queue";

    @Test
    public void publish() throws Exception {
//        - 获取Connection
        Connection connection = MQConnUtil.getConn();

//        - 创建Channel
        Channel channel = connection.createChannel();

//        - 创建Exchange（无需创建）

//        - 发送消息到Exchange，并设置消息的RoutingKey
        for (int i = 0; i < 10; i++) {
            String msg = "work~~~~~" + i;
            channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
        }
        System.out.println("发送10条消息成功!!");

//        - 释放资源
        channel.close();
        connection.close();
    }

}
